
class Solution {
public:
    /**
     * 
     * @param n int整型 
     * @return string字符串vector
     */
    void recursion(int left, int right, string temp, vector<string>& res, int n){
        //左右括号都用完了，就加入结果
        if(left == n && right == n){
            res.push_back(temp);
            return;
        }
        //使用一次左括号
        if(left < n)
            recursion(left + 1, right, temp + "(", res, n);       
        if(right < n && left > right)
            recursion(left, right + 1, temp + ")", res, n);
    }

    vector<string> generateParenthesis(int n) {
        // 记录结果
        vector<string> res;
        //记录每次组装的字符串
        string temp;
        //递归
        recursion(0, 0, temp, res, n);
        return res;        
    }
};